-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add Async RedisCluster #2099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Async RedisCluster #2099
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2099 +/- ##
==========================================
+ Coverage 92.48% 92.66% +0.17%
==========================================
Files 105 108 +3
Lines 25197 27174 +1977
==========================================
+ Hits 23304 25180 +1876
- Misses 1893 1994 +101
Continue to review full report at Codecov.
|
@utkarshgupta137 This looks like a great PR in progress. Just checking if you meant for it to be draft. |
Yeah. I've not modified any documentation or added tests and I've only done basic testing. |
23cc596
to
ea79c95
Compare
@chayim @dvora-h @Andrew-Chen-Wan @Grokzen I've got all the tests running, but there are some warnings that may need to be addressed. I've divided the PR into 3 commits:
|
@dvora-h Can you give @utkarshgupta137 a hand with this? How about integrating the documentation side - adding cluster examples, etc. @utkarshgupta137 What else can we do to help? The last piece I see is the test_acl_log failure, at least from a starting position. |
That test is only failing on 3.6. If you see the cancelled 3.7+ tests, it hasn't failed in that case. Also ran normally on my amd64 mac py3.9. The failure seems to be related to client closing. There are also warnings about the client not closing properly from other tests. Both of the problems are probably related. If anyone could verify the |
Looks like the tests are failing on 3.6 due to related issue aio-libs-abandoned/aioredis-py#1273. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just an initial read through. This looks great!
gotcha. Cluster has an initialize async method. You can make a task that takes a ClusterNode as a param every time node manager creates a NodeCluster. Create a while loop with some small sleep time (because asyncio) that awaits for the task to be canceled. Cancel it when it needs to be removed. Once canceled (it’s an exception in the task itself), you can perform any disconnection on the ClusterNode within that loop.
Something like:
try:
…
except CanceledError (I think):
pass
finally:
# disconnect
________________________________
From: Utkarsh Gupta ***@***.***>
Sent: Thursday, April 14, 2022 7:56:21 AM
To: redis/redis-py ***@***.***>
Cc: Andrew Chen Wang ***@***.***>; Mention ***@***.***>
Subject: Re: [redis/redis-py] Add Async RedisCluster (PR #2099)
@utkarshgupta137 commented on this pull request.
________________________________
In redis/asyncio/cluster.py<#2099 (comment)>:
+ )
+
+ def __eq__(self, obj):
+ return isinstance(obj, ClusterNode) and obj.name == self.name
+
+ def __del__(self):
+ try:
+ if self.redis_connection is not None:
+ loop = asyncio.get_event_loop()
+ coro = self.redis_connection.close(True)
+ if loop.is_running():
+ loop.create_task(coro)
+ else:
+ loop.run_until_complete(coro)
+ except Exception:
+ pass
No, that's the problem. In case of MOVED errors or persistent connection errors, the nodes_manager would be reinitialized, which could lead to some Nodes being removed.
—
Reply to this email directly, view it on GitHub<#2099 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AOLG4VQ5BNWJ72PN5SXJ6PTVFABWLANCNFSM5S77AVMQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@chayim @Andrew-Chen-Wang Most of the warnings have been resolved. The test_acl_log is still failing on 3.6, I'll check it tomorrow. |
@chayim when are we dropping Python 3.6? Or start marking it as unneeded for merging. |
test_acl_log is fixed now. It was failing because I had an empty yield statement in async def. |
640e9ec
to
7537178
Compare
@utkarshgupta137 Dropping python 3.6 support isn't a 4.2 thing, but could happen as we start to clean up the repo in 4.3+/5.x. There's a lot of 3.6 out there - even if I'd love to be 3.7+. |
@@ -41,6 +42,10 @@ | |||
autosectionlabel_prefix_document = True | |||
autosectionlabel_maxdepth = 2 | |||
|
|||
# AutodocTypehints settings. | |||
always_document_param_types = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Had no idea this was an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@utkarshgupta137 This is really, really close. I added tiny comments - that to be honest, I'm okay with eliminating. Also, it works nicely :).
I think we can get this in a 4.3.0 release, immediately - as this necessitates a minor version bump. WDYT?
82abb20
to
9f8e57a
Compare
@chayim Can you hold off on merging this? I think making it thread-safe is trivial. |
Of course - but beware of scope creep. |
@chayim According to https://docs.python.org/3/library/asyncio-dev.html#asyncio-multithreading, |
@utkarshgupta137 I am no longer part of working with redis clients here or in my own repo any longer. I have handed the future of cluster related things to this repo so there won't be any need for me to review or be a part of any cluster related development :) The major good part of this PR is that you get asyncio into here, the major pain going forward tho will be that it seems you have to clone and duplicate the normal code and asyncio code =( I am sure maintaining that is going to be a much bigger job after this get in. Is the plan to require any future modifications and contributions to make both normal and asyncio code compatible with any change? or will it be more on a "lets hope it will happen" basis? |
@Grokzen I will carry over all the changes/optimisations I've made to async to the sync client soon. For the long term, there is a discussion in #2119 regarding moving to sansio approach. It is IMO a much better approach for supporting both sync/async & I can port the cluster code to it if we go with it. |
I mean I use async and threading all the time - even if I shouldn't. But, never in prod. I think we're ready to merge this. @dvora-h ready for the new version when you are. |
@utkarshgupta137 I just merged master in. We're very, very close! |
this looks great. thanks @utkarshgupta137 !!!! |
Does this support pipeline by any chance? |
Not at the moment. I just wanted to add basic support first and see if there are any issues. I will try to add pipeline support as well as a few other missing features like locks, pubsub, monitor etc. |
Thanks @utkarshgupta137. What you have done on the async support is really helpful! Our project relies heavily on pipelines, so I wonder if there's any rough timeline you have in mind for these supports, or if there's any workaround for the time-being. |
I've been considering switching to pipelines as well. But between me writing the code, tests, review, & release, it may take 2-3 weeks. In the meantime, I think there are a couple of other packages with async cluster like aredis which may've support for it, but I'm not sure. |
Oof, there's a lot of copy-paste in this PR... My PyCharm's Locate Duplicates is just lighting up :( |
Pull Request check-list
$ tox
pass with this change (including linting)?Description of change
Add Async Redis Cluster Client